#!/bin/sh

STREAMER_APP="streamer"

. /usr/share/common

start() {
	echo_title "Starting Record service"

	if pidof -o $$ $DAEMON > /dev/null; then
		echo_error "$DAEMON is already running"
		exit 1
	fi

	if ! pidof $STREAMER_APP; then
		echo_error "Streamer is not running"
		exit 1
	fi

	if [ "true" != "$record_enabled" ]; then
		echo_error "Recording disabled"
		exit 1
	fi

	start_daemon
}

stop() {
	echo_title "Stopping Recording service"

	stop_daemon

	find /tmp/ -name "record.*" -maxdepth 0 -delete
}

case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;

	restart)
		stop
		sleep 1
		start
		;;
	*)
		usage "{start|stop|restart}"
		;;
esac

exit 0
